package com.netty.client.handler;

import com.netty.common.protocol.common.TestPacket;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class TestHandler extends SimpleChannelInboundHandler<TestPacket> {

    protected ChannelHandlerContext thisCtx;
    @Override
    protected void channelRead0(ChannelHandlerContext cxt, TestPacket testPacket) {
        thisCtx = cxt;
        System.out.println("收到客户端发来的消息：" + testPacket.getMessage());
        TestPacket testPacket1 = new TestPacket("change");
        cxt.channel().writeAndFlush(testPacket1)
                .addListener((ChannelFutureListener) channelFuture -> System.out.println("发送成功"));
    }

}
